/***************************************************************************
 创建者: 华磊
 开始时间: 2018.8.14
 copyright: (C) 华友高科
 修改说明: (每次有修改就添加一条，带有 修改人，修改时间，修改描述)
 example (1) hualei 2017.5.8 类的具体实现代码编写

 ***************************************************************************/
#include "programset.h"
#include "programregexp.h"
//#include <math.h>
#include <algorithm>

enum ENUM_CF_FLAG
{
    EM_CF_OFF,
    EM_CF_ON,
    EM_CF_FAIL,
    EM_CF_END
};


ProgramSet::ProgramSet()
{
    errCmdFlag = EM_CF_OFF;

    userInfoErr = EM_CF_OFF;
    rFileErr = EM_CF_OFF;
    prFileErr = EM_CF_OFF;
    plFileErr = EM_CF_OFF;

    regRList.resize(REG_SIZE);
    memset(regRList.begin(),0,REG_SIZE);

    arList.resize(AR_SIZE);
    memset(arList.begin(),0,AR_SIZE);
    prList.resize(AR_SIZE);
    memset(prList.begin(),0,AR_SIZE);

    pr2List.resize(AR_SIZE);
    for(int i = 0; i < AR_SIZE;i++)
    {
        pr2List[i].resize(AR_SIZE);
        for(int j = 0; j < pr2List[i].size();j++)
        {
            pr2List[i][j] = 0;
        }
    }

    plList.resize(PL_SIZE);
    for(int i = 0; i < PL_SIZE;i++)
    {
        plList[i].resize(3);
        for(int j = 0; j < plList[i].size();j++)
        {
            plList[i][j] = 0;
        }
    }

    Gi.resize(AR_SIZE);
    memset(Gi.begin(),0,AR_SIZE);
    Go.resize(AR_SIZE);
    memset(Go.begin(),0,AR_SIZE);
    Ai.resize(AR_SIZE);
    memset(Ai.begin(),0,AR_SIZE);
    Ao.resize(AR_SIZE);
    memset(Ao.begin(),0,AR_SIZE);
    Di.resize(AR_SIZE);
    memset(Di.begin(),0,AR_SIZE);
    Do.resize(AR_SIZE);
    memset(Do.begin(),0,AR_SIZE);
    Ri.resize(AR_SIZE);
    memset(Ri.begin(),0,AR_SIZE);
    Ro.resize(AR_SIZE);
    memset(Ro.begin(),0,AR_SIZE);
    Si.resize(AR_SIZE);
    memset(Si.begin(),0,AR_SIZE);
    So.resize(AR_SIZE);
    memset(So.begin(),0,AR_SIZE);
    Ui.resize(AR_SIZE);
    memset(Ui.begin(),0,AR_SIZE);
    Uo.resize(AR_SIZE);
    memset(Uo.begin(),0,AR_SIZE);
    timer_overflow.resize(AR_SIZE);
    memset(timer_overflow.begin(),0,AR_SIZE);

    uframeList.resize(AR_SIZE);
    memset(uframeList.begin(),0,AR_SIZE);
    utoolList.resize(AR_SIZE);
    memset(utoolList.begin(),0,AR_SIZE);

    //    readUserInfo();

    regPrList.resize(REG_SIZE);

    startTime.resize(TIMER_SIZE);
    endTime.resize(TIMER_SIZE);

    timerProcessType.resize(TIMER_SIZE);
    memset(timerProcessType.begin(),0,TIMER_SIZE);

 //   timerOverFlowType.resize(TIMER_SIZE);

    countTimer.resize(TIMER_SIZE);
    memset(countTimer.begin(),0,TIMER_SIZE);

//    initCommonRegExp();
//    initialInstructionSimpleRegExp();
    programRegExp=new ProgramRegExp;
//    initRegValue();
}



ProgramSet::~ProgramSet()
{

}

int ProgramSet::getProgramString_byName(QString fileName,QVector<QString>  &programStrings)
{
    qDebug()<<"ProgramSet::getProgramString_byName, "<<fileName;
    mutex_programString.lock();
    programStrings.clear();
    qDebug()<<"this[0].size()= "<<this[0].size();
    for(int i=0;i<this[0].size();i++)
    {
        qDebug()<<"this[0][i].thisProgramName= "<<this[0][i].thisProgramName;
        if(this[0][i].thisProgramName==fileName)
        {
            programStrings=this[0][i].programStrList;
            mutex_programString.unlock();
            return 1;
        }

    }
    mutex_programString.unlock();
    return -1;
}

int ProgramSet::getProgramString(QVector<QVector<QString> > &programStrings)
{
    mutex_programString.lock();
    programStrings.clear();

    for(int i=0;i<this[0].size();i++)
    {
        programStrings.append(this[0][i].programStrList);
    }
    mutex_programString.unlock();
    return 1;
}



int ProgramSet::transferTextInstructionToStructData(QVector <QString> strList,int programNum,
                                                    QString programName,int programStatus,int _robotId)
{
    robotId = _robotId;

    if (programNum>=this[0].size())
    {
        this[0].resize(this[0].size()+1);
    }

    float time1 = 0.0;
    float time2 = 0.0;


    this[0][programNum].resize(strList.size());

    this[0][programNum].thisProgramName = programName;
    mutex_programString.lock();
    this[0][programNum].programStrList=strList;
    mutex_programString.unlock();

    int lineSize = strList.size();
    int returnFlag =0;
//    qDebug()<<"regg how much line:"<<lineNum<<"====programNum==="<<programNum<<"\n\n";
    for(int lineIndex=0;lineIndex<lineSize;lineIndex++)
    {
//        qDebug() << "==programStatus=="<<programStatus<<"==currentId=="<<QThread::currentThreadId();
        int pat;
//        qDebug() << "**str[j]*"<<strList[j]<<endl;

//        gettimeofday(&patExectStartTime,NULL);
        pat = programRegExp->patExtractInstructionType(strList[lineIndex]);
//        gettimeofday(&patExectEndTime,NULL);

//        time1 += countIntervalTime(patExectStartTime,patExectEndTime,j,1);

//        qDebug()<<"===指令类型: "<<pat <<", 行号: "<<   j  << "====xxx指令原文: "<<strList[j];


        if(pat==ERR)
        {
            qDebug()<<"====Error: 指令类型识别失败"<<"program"<<programNum<<"line"<<lineIndex+1<<":"
                   <<strList[lineIndex];
            returnFlag = lineIndex+1;
            return returnFlag;
        }
//        gettimeofday(&patStartTime,NULL);
        this[0][programNum][lineIndex].type=(INSTRUCTION_TYPE)pat;
        this[0][programNum][lineIndex].lineStr=strList[lineIndex];
        if(D_MAX_PARSED_LINE>lineIndex)
        {
            this[0][programNum][lineIndex].isParsed=true;
            this[0][programNum].needToParseLine=lineIndex+1;

        }
        else
        {
            this[0][programNum][lineIndex].isParsed=false;
            continue;
        }
        switch(pat)
        {
        case INS_AXIS_MOVE:
        {
            if(1!=programRegExp->patAxisMove(strList[lineIndex],this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case MOTION:
        {
            QString forwardLineString;
            if(lineIndex>0)
            {
                forwardLineString=strList[lineIndex-1];
            }

            if(1!=programRegExp->patMotion(strList[lineIndex],forwardLineString,this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }

            break;
        }
        case JUMP:
        {
            programRegExp->patJump(strList[lineIndex],this[0][programNum][lineIndex]);
            break;
        }
        case LABEL:
        {
            programRegExp->patLabel(strList[lineIndex],this[0][programNum][lineIndex]);
            break;
        }
        case IO:
        {
            programRegExp->patIo(strList[lineIndex],this[0][programNum][lineIndex]);
            break;
        }
        case CALL:
        {
            programRegExp->patCall(strList[lineIndex],this[0][programNum][lineIndex]);
            break;
        }
        case IF:
        {
            programRegExp->patIf(strList[lineIndex],lineIndex,this[0][programNum]);
            break;
        }
        case SELECT:
        {
            programRegExp->patSelect(strList[lineIndex],lineIndex,this[0][programNum]);
            break;
        }
        case RUN:
        {
            programRegExp->patRun(strList[lineIndex],this[0][programNum][lineIndex]);
            break;
        }
        case FOR:
        {
//            qDebug()<< "For***coming***"<<endl;
            programRegExp->patFor(strList[lineIndex],this[0][programNum][lineIndex]);
            break;
        }
        case REG:
        {
            programRegExp->patRegister(strList[lineIndex],this[0][programNum][lineIndex]);
            break;
        }
        case INS_PALLET:
        {
            programRegExp->patPal(strList[lineIndex],this[0][programNum][lineIndex]);
            break;
        }
        case COORDINATE:
        {
            programRegExp->patCoordinate(strList[lineIndex],this[0][programNum][lineIndex]);
            break;
        }
        case WAIT:
        {
            programRegExp->patWait(strList[lineIndex],this[0][programNum][lineIndex]);
            break;
        }
        case PAUSE:
        {
            programRegExp->patPause(strList[lineIndex],this[0][programNum][lineIndex]);
            break;
        }
        case ABORT:
        {
            programRegExp->patAbort(strList[lineIndex],this[0][programNum][lineIndex]);
            break;
        }
        case END:
        {
            programRegExp->patEnd(strList[lineIndex],this[0][programNum][lineIndex]);
            break;
        }
        case UALM:
        {
            programRegExp->patUalm(strList[lineIndex],this[0][programNum][lineIndex]);
            break;
        }
        case MESSAGE:
        {
            programRegExp->patMessage(strList[lineIndex],this[0][programNum][lineIndex]);
            break;
        }
        case OVERRIDE:
        {
            programRegExp->patOverride(strList[lineIndex],this[0][programNum][lineIndex]);
            break;
        }
        case TIMER:
        {
            programRegExp->patTimer(strList[lineIndex],this[0][programNum][lineIndex]);
            break;
        }
        case RSR:
        {
            programRegExp->patRsr(strList[lineIndex],this[0][programNum][lineIndex]);
            break;
        }
        case ANOTATION:
        {
//            qDebug() << __FUNCTION__<<"*******"<<__LINE__<<"====ANOTATION====="<<endl;
            programRegExp->patAnnotation(strList[lineIndex],this[0][programNum][lineIndex]);
            break;
        }
        case GRIPPER:
        {
            programRegExp->patGripper(strList[lineIndex],this[0][programNum][lineIndex]);
            break;
        }
        case MODBUS_START:
        {
            if(1!=programRegExp->patModbusStart(strList[lineIndex],this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case MODBUS_READ:
        {
            if(1!=programRegExp->patModbusRead(strList[lineIndex],this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case MODBUS_WRITE:
        {
            if(1!=programRegExp->patModbusWrite(strList[lineIndex],this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case MOVE_MAG:
        {
            programRegExp->patMoveMag(strList[lineIndex],this[0][programNum][lineIndex]);
            break;
        }
        case MOVE_FREE:
        {
            programRegExp->patMoveFree(strList[lineIndex],this[0][programNum][lineIndex]);
            break;
        }
       case TCP_START:
        {
            programRegExp->patTcpStart(strList[lineIndex],this[0][programNum][lineIndex]);
            break;
        }
       case TCP_READ:
       {
           programRegExp->patTcpRead(strList[lineIndex],this[0][programNum][lineIndex]);
           break;
       }
       case TCP_WRITE:
       {
           programRegExp->patTcpWrite(strList[lineIndex],this[0][programNum][lineIndex]);
           break;
       }
        case MUSIC:
        {
            programRegExp->patMusic(strList[lineIndex],this[0][programNum][lineIndex]);
            break;
        }
        case SET_ODOM:
        {
            programRegExp->patSetOdom(strList[lineIndex],this[0][programNum][lineIndex]);
            break;
        }
        case CHARGING:          // 充电指令匹配解析
        {
            programRegExp->patCharging(strList[lineIndex],this[0][programNum][lineIndex]);
            break;
        }
        case LIFT:              // 升降机构匹配解析
        {
            programRegExp->patLift(strList[lineIndex],this[0][programNum][lineIndex]);
            break;
        }
        case LOAD_MAP:              // 记载地图匹配解析
        {
            programRegExp->patLoadMap(strList[lineIndex],this[0][programNum][lineIndex]);
            break;
        }
        case CHECK_BATTERY:              // 电量匹配解析
        {
            programRegExp->patCheckBattery(strList[lineIndex],this[0][programNum][lineIndex]);
            break;
        }
        case WAIT_COMAND:              // 呼叫匹配解析
        {
            programRegExp->patWaitCommand(strList[lineIndex],this[0][programNum][lineIndex]);
            break;
        }
        case ROBOT_MOVE:              // 机械手控制解析
        {
            programRegExp->patRobotMove(strList[lineIndex],this[0][programNum][lineIndex]);
            break;
        }
        case ROLLER:              // 机械手控制解析
        {
            programRegExp->patRoller(strList[lineIndex],this[0][programNum][lineIndex]);
            break;
        }
        case INS_VISION_RUN:
        {
            if(1!=programRegExp->patVisionRun(strList[lineIndex],this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_VISION_TRIGGER:
        {

            if(1!=programRegExp->patVisionTrigger(strList[lineIndex],this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_VISION_GET_DATA:
        {
            if(1!=programRegExp->patVisionGetData(strList[lineIndex],this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_VISION_CLEAR_DATA:
        {
            if(1!=programRegExp->patVisionClearData(strList[lineIndex],this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_TRACK_START:
        {
            if(1!=programRegExp->patTrackStart(strList[lineIndex],this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_TRACK_END:
        {
            if(1!=programRegExp->patTrackEnd(strList[lineIndex],this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_TRACK_GET_DATA:
        {
            if(1!=programRegExp->patTrackGetData(strList[lineIndex],this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_REG_PR:
        {
            if(1!=programRegExp->patRegPr(strList[lineIndex],this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_REG_PL:
        {
            if(1!=programRegExp->patRegPl(strList[lineIndex],this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_WELD_START://拓展新指令Fundation增加代码20191122hualei
        {
            if(1!=programRegExp->patWeldStart(strList[lineIndex],this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_WELD_END:
        {
            if(1!=programRegExp->patWeldEnd(strList[lineIndex],this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }

        case INS_WEAVE:
        {
            if(1!=programRegExp->patWeave(strList[lineIndex],this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_WEAVE_END:
        {
            if(1!=programRegExp->patWeaveEnd(strList[lineIndex],this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_TRACKWELD_TAST:
        {
            if(1!=programRegExp->patTrackWeldTast(strList[lineIndex],this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_TRACKWELD_END:
        {
            if(1!=programRegExp->patTrackWeldEnd(strList[lineIndex],this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_WATCHDI:
        {
            if(1!=programRegExp->patWatchDI(strList[lineIndex],this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_LASER_CAMERA_FETCHPOINT:
        {
            if(1!=programRegExp->patLaserCameraFetchPoint(strList[lineIndex],this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_LASER_CAMERA_CTRL:
        {
            if(1!=programRegExp->patLaserCameraControl(strList[lineIndex],this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_LASER_CAMERA_TRACK:
        {
            if(1!=programRegExp->patLaserCameraTrack(strList[lineIndex],this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_LASER_SCAN:
        {
            if(1!=programRegExp->patLaserScan(strList[lineIndex],this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_BUFFER_MOVE:
        {
            if(1!=programRegExp->patBufferMove(strList[lineIndex],this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        default:
        {
            programRegExp->patErr(strList[lineIndex],this[0][programNum][lineIndex]);
            returnFlag = lineIndex+1;
            return returnFlag;
        }
        }
//        gettimeofday(&patEndTime,NULL);

//        time2 += countIntervalTime(patStartTime,patEndTime,j,2);
    }

//    qDebug() << "==time1==="<<time1<<"==time2=="<<time2;

    return returnFlag;
}

int ProgramSet::transferTextInstructionToStructData_onestep(int programNum)
{

    if (programNum>=this[0].size())
    {
       return 0;
    }

    int lineSize = std::min(this[0][programNum].size(),this[0][programNum].needToParseLine+D_ONE_PARSE_LINE_SIZE);
    int returnFlag =1;

    for(int lineIndex=this[0][programNum].needToParseLine;lineIndex<lineSize;lineIndex++)
    {
        this[0][programNum].needToParseLine++;
        this[0][programNum][lineIndex].isParsed=true;
        switch(this[0][programNum][lineIndex].type)
        {
        case INS_AXIS_MOVE:
        {
            if(1!=programRegExp->patAxisMove(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case MOTION:
        {
            QString forwardLineString;
            if(lineIndex>0)
            {
                forwardLineString=this[0][programNum][lineIndex-1].lineStr;
            }

            if(1!=programRegExp->patMotion(this[0][programNum][lineIndex].lineStr,forwardLineString,this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }

            break;
        }
        case JUMP:
        {
            programRegExp->patJump(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
            break;
        }
        case LABEL:
        {
            programRegExp->patLabel(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
            break;
        }
        case IO:
        {
            programRegExp->patIo(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
            break;
        }
        case CALL:
        {
            programRegExp->patCall(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
            break;
        }
        case IF:
        {
            programRegExp->patIf(this[0][programNum][lineIndex].lineStr,lineIndex,this[0][programNum]);
            break;
        }
        case SELECT:
        {
            programRegExp->patSelect(this[0][programNum][lineIndex].lineStr,lineIndex,this[0][programNum]);
            break;
        }
        case RUN:
        {
            programRegExp->patRun(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
            break;
        }
        case FOR:
        {
//            qDebug()<< "For***coming***"<<endl;
            programRegExp->patFor(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
            break;
        }
        case REG:
        {
            programRegExp->patRegister(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
            break;
        }
        case INS_PALLET:
        {
            programRegExp->patPal(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
            break;
        }
        case COORDINATE:
        {
            programRegExp->patCoordinate(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
            break;
        }
        case WAIT:
        {
            programRegExp->patWait(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
            break;
        }
        case PAUSE:
        {
            programRegExp->patPause(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
            break;
        }
        case ABORT:
        {
            programRegExp->patAbort(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
            break;
        }
        case END:
        {
            programRegExp->patEnd(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
            break;
        }
        case UALM:
        {
            programRegExp->patUalm(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
            break;
        }
        case MESSAGE:
        {
            programRegExp->patMessage(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
            break;
        }
        case OVERRIDE:
        {
            programRegExp->patOverride(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
            break;
        }
        case TIMER:
        {
            programRegExp->patTimer(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
            break;
        }
        case RSR:
        {
            programRegExp->patRsr(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
            break;
        }
        case ANOTATION:
        {
//            qDebug() << __FUNCTION__<<"*******"<<__LINE__<<"====ANOTATION====="<<endl;
            programRegExp->patAnnotation(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
            break;
        }
        case GRIPPER:
        {
            programRegExp->patGripper(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
            break;
        }
        case MODBUS_START:
        {
            if(1!=programRegExp->patModbusStart(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case MODBUS_READ:
        {
            if(1!=programRegExp->patModbusRead(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case MODBUS_WRITE:
        {
            if(1!=programRegExp->patModbusWrite(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case MOVE_MAG:
        {
            programRegExp->patMoveMag(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
            break;
        }
        case MOVE_FREE:
        {
            programRegExp->patMoveFree(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
            break;
        }
       case TCP_START:
        {
            programRegExp->patTcpStart(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
            break;
        }
       case TCP_READ:
       {
           programRegExp->patTcpRead(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
           break;
       }
       case TCP_WRITE:
       {
           programRegExp->patTcpWrite(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
           break;
       }
        case MUSIC:
        {
            programRegExp->patMusic(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
            break;
        }
        case SET_ODOM:
        {
            programRegExp->patSetOdom(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
            break;
        }
        case CHARGING:          // 充电指令匹配解析
        {
            programRegExp->patCharging(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
            break;
        }
        case LIFT:              // 升降机构匹配解析
        {
            programRegExp->patLift(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
            break;
        }
        case LOAD_MAP:              // 记载地图匹配解析
        {
            programRegExp->patLoadMap(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
            break;
        }
        case CHECK_BATTERY:              // 电量匹配解析
        {
            programRegExp->patCheckBattery(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
            break;
        }
        case WAIT_COMAND:              // 呼叫匹配解析
        {
            programRegExp->patWaitCommand(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
            break;
        }
        case ROBOT_MOVE:              // 机械手控制解析
        {
            programRegExp->patRobotMove(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
            break;
        }
        case ROLLER:              // 机械手控制解析
        {
            programRegExp->patRoller(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
            break;
        }
        case INS_VISION_RUN:
        {
            if(1!=programRegExp->patVisionRun(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_VISION_TRIGGER:
        {

            if(1!=programRegExp->patVisionTrigger(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_VISION_GET_DATA:
        {
            if(1!=programRegExp->patVisionGetData(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_VISION_CLEAR_DATA:
        {
            if(1!=programRegExp->patVisionClearData(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_TRACK_START:
        {
            if(1!=programRegExp->patTrackStart(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_TRACK_END:
        {
            if(1!=programRegExp->patTrackEnd(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_TRACK_GET_DATA:
        {
            if(1!=programRegExp->patTrackGetData(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_REG_PR:
        {
            if(1!=programRegExp->patRegPr(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_REG_PL:
        {
            if(1!=programRegExp->patRegPl(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_WELD_START://拓展新指令Fundation增加代码20191122hualei
        {
            if(1!=programRegExp->patWeldStart(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_WELD_END:
        {
            if(1!=programRegExp->patWeldEnd(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }

        case INS_WEAVE:
        {
            if(1!=programRegExp->patWeave(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_WEAVE_END:
        {
            if(1!=programRegExp->patWeaveEnd(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_TRACKWELD_TAST:
        {
            if(1!=programRegExp->patTrackWeldTast(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_TRACKWELD_END:
        {
            if(1!=programRegExp->patTrackWeldEnd(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_WATCHDI:
        {
            if(1!=programRegExp->patWatchDI(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_LASER_SCAN:
        {
            if(1!=programRegExp->patLaserScan(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        case INS_BUFFER_MOVE:
        {
            if(1!=programRegExp->patBufferMove(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]))
            {
                returnFlag = lineIndex+1;
                return returnFlag;
            }
            break;
        }
        default:
        {
            programRegExp->patErr(this[0][programNum][lineIndex].lineStr,this[0][programNum][lineIndex]);
            break;
        }
        }
//        gettimeofday(&patEndTime,NULL);
//        time2 += countIntervalTime(patStartTime,patEndTime,j,2);
    }

//    qDebug() << "==time1==="<<time1<<"==time2=="<<time2;

    return returnFlag;
}

int ProgramSet::examParse(int programNum, int lineId)
{
    if (programNum>=this[0].size())
    {
       return 0;
    }
    if (lineId>=this[0][programNum].size())
    {
       return 0;
    }

    int needLine=std::min(lineId+D_CASH_PARSE_COUNT,this[0][programNum].size()-1);

    while(false==this[0][programNum][needLine].isParsed)
    {
        int tmpKey=transferTextInstructionToStructData_onestep(programNum);
        if(1!=tmpKey)
        {
            return tmpKey;
        }
    }
    return 1;
}


